package com.suray.attendance.common.utils;

import org.slf4j.LoggerFactory;

public class LoggerUtil {
    /**
     * print to error file
     * @param type:信息类型
     * @param param:信息参数
     * @param res:保留（可以为null）
     * @param str:具体信息
     * @param clazz:调用类
     */
    public static void error(ModuleType module, LoggerType type, Object param, Object res, String str, Class<?> clazz) {
        error(generalMessage(module, type, param, res, str), clazz);
    }

    public static void error(ModuleType module, LoggerType type, Object param, Object res, String str, Object obj1, Object obj2, Class<?> clazz) {
        LoggerFactory.getLogger(clazz).error(generalMessage(module, type, param, res, str), obj1, obj2);
    }

    public static void info(String str, Class<?> clazz) {
        LoggerFactory.getLogger(clazz).info(str);
    }

    public static void warn(String str, Class<?> clazz) {
        LoggerFactory.getLogger(clazz).warn(str);
    }

    public static void debug(String str, Class<?> clazz) {
        LoggerFactory.getLogger(clazz).warn(str);
    }

    public static void error(String str, Class<?> clazz) {
        LoggerFactory.getLogger(clazz).error(str);
    }

    public static void error(String str, Object obj1, Object obj2, Class<?> clazz) {
        LoggerFactory.getLogger(clazz).error(str, obj1, obj2);
    }

    private static String generalMessage(ModuleType module, LoggerType type, Object param, Object res, String str) {
        if (res != null) {
            return module + "-" + type + "-" + "(" + param + ")" + "-" + res + "-->" + str;
        }

        return module + "-" + type + "-" + "(" + param + ")-->" + str;
    }
}
